package com.health.db.service.user.impl;
 
import java.util.List;

import org.apache.commons.lang3.StringUtils;

import com.health.db.dao.user.IUserLISTDao;
import com.health.db.model.UserLIST;
import com.health.db.model.UserLISTTemp;
import com.health.db.service.user.IUserLISTService;
import com.health.mapp.service.SpringContextUtil;

public class UserLISTServiceImpl implements IUserLISTService {

 

	private IUserLISTDao userLISTDao;
	
	//IUserCardListService userCardListService = SpringContextUtil.getBean("userCardListService");

	@Override
	public UserLIST selectByUserId(Long userId) {

		UserLIST uList = userLISTDao.selectByUserId( userId);
		// TODO Auto-generated method stub
		return uList;
	}

	@Override
	public int insertUser(UserLIST userLIST) {
		int result = -1;

		result = userLISTDao.insertUser( userLIST);

		//userCardListService.activeUserCardByRecharge(userId, currGoodsOrder.getGoodsid());
		
		return result;
	}
	
	@Override
	public int insertUser(UserLIST userLIST,Long cardTypeId) {
		// TODO Auto-generated method stub
		int result = -1;
		userLISTDao.insertUser( userLIST);
		//IUserCardListService userCardListService = SpringContextUtil.getBean("userCardListService");
		//userCardListService.activeUserCardByRecharge(userLIST.getUserid(), cardTypeId);
		return result;
	}
	
	
	@Override
	public int updateByPrimaryKey(UserLIST userLIST) {
		
		int result = -1;
		result = userLISTDao.updateByPrimaryKey( userLIST);

		return  result;
	}


	@Override
	public int updatePassword(UserLIST userLIST) {
		int result = -1;
		result = userLISTDao.updatePassword( userLIST);
		return result;
	}

	 

	public IUserLISTDao getUserLISTDao() {
		return userLISTDao;
	}

	public void setUserLISTDao(IUserLISTDao userLISTDao) {
		this.userLISTDao = userLISTDao;
	}

	@Override
	public UserLIST selectByUserNo(String userNo) {
		// TODO Auto-generated method stub
		return 	 userLISTDao.selectByUserNo(userNo);
	}

	@Override
	public UserLISTTemp selectUserLISTTempByUserNo(String userNo) {
		// TODO Auto-generated method stub
		UserLIST userLIST=selectByUserNo(userNo);
		if(null!=userLIST)
		{
			UserLISTTemp userLISTTemp=new UserLISTTemp();
			userLISTTemp.setUserId( String.valueOf(userLIST.getUserid()));
			userLISTTemp.setUserName(userLIST.getUserName());
			userLISTTemp.setUserPhone(userLIST.getUserNo());
			userLISTTemp.setRegTime(userLIST.getRegisterDate());
			userLISTTemp.setIcon(userLIST.getIconUrl());
			userLISTTemp.setToken(userLIST.getApptoken());
			userLISTTemp.setIsExportFlag(userLIST.getIsExportFlag());
			userLISTTemp.setUserTypeId(userLIST.getTypeid());
			return userLISTTemp;
		}
		return null;
	}

	@Override
	public int updateLoginInfo(UserLIST userLIST) {
		
		if (null==userLIST.getLoginDatetime()&&null==userLIST.getLogoutDatetime()) {
			return 0;
		}else{
			return userLISTDao.updateLoginInfo(userLIST);
		}
		
	}

	@Override
	public List<UserLIST> selectByWXOpenid(String wxopenid) {
		
		if (StringUtils.isBlank(wxopenid)) {
		
			return null;
		}else{
		
		return userLISTDao.selectByWXOpenId(wxopenid);
		}
	}

	@Override
	public List<UserLIST> selectByBusinessCode(String businessCode) {
		// TODO Auto-generated method stub
		return userLISTDao.selectByBusinessCode(businessCode);
	}


}
